package view;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.Font;


public class WorldMapGUI extends AbstractGUI
{

	private ArrayList <JButton> worldMapButtons;
	private JPanel contentPane=null;
	SearchPhotoGUI windowToSetWithLocation;
	
	public WorldMapGUI(SearchPhotoGUI windowToSetWithLocation)
	{
		//set frame
		super();
		setResizable(false);
	    this.setLocationByPlatform(true);
	    this.setLocationRelativeTo(null); //This will center the JFrame in the middle of the screen
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        this.setTitle("World Map Window");
        this.setBounds(500, 200,1250,820);
        
        validate();
        
        //save the search view 
        this.windowToSetWithLocation = windowToSetWithLocation;
        
        //set content pane
        JLayeredPane layeredPane = new JLayeredPane();
        getContentPane().add(layeredPane, BorderLayout.CENTER);
       
        //initialize buttons
        worldMapButtons = new ArrayList<JButton>();
        JButton btnz1 = new JButton("z1");
        btnz1.setBounds(662, 369, 35, 29);
        layeredPane.add(btnz1);
        //set the button transparent
        btnz1.setOpaque(false);
        btnz1.setContentAreaFilled(false);
        btnz1.setBorderPainted(false);
        worldMapButtons.add(btnz1);
        
        JButton btnz2 = new JButton("z2");
        btnz2.setBounds(686, 352, 20, 19);
        layeredPane.add(btnz2);
        //set the button transparent
        btnz2.setOpaque(false);
        btnz2.setContentAreaFilled(false);
        btnz2.setBorderPainted(false);
        worldMapButtons.add(btnz2);
        
        JButton btnz3 = new JButton("z3"); //brazil
        btnz3.setBounds(388, 483, 72, 63);
        layeredPane.add(btnz3);
        //set the button transparent
        btnz3.setOpaque(false);
        btnz3.setContentAreaFilled(false);
        btnz3.setBorderPainted(false);
        worldMapButtons.add(btnz3);
        
        JButton btnz4 = new JButton("z4");
        btnz4.setBounds(297, 316, 27, 72);
        layeredPane.add(btnz4);
        //set the button transparent
        btnz4.setOpaque(false);
        btnz4.setContentAreaFilled(false);
        btnz4.setBorderPainted(false);
        worldMapButtons.add(btnz4);
        
        JButton btnz5 = new JButton("z5");
        btnz5.setBounds(686, 65, 500, 203);
        layeredPane.add(btnz5);
        //set the button transparent
        btnz5.setOpaque(false);
        btnz5.setContentAreaFilled(false);
        btnz5.setBorderPainted(false);
        worldMapButtons.add(btnz5);
        
        JButton btnz6 = new JButton("z6");
        btnz6.setBounds(166, 325, 128, 55);
        layeredPane.add(btnz6);
        //set the button transparent
        btnz6.setOpaque(false);
        btnz6.setContentAreaFilled(false);
        btnz6.setBorderPainted(false);
        worldMapButtons.add(btnz6);
        
        JButton btnz7 = new JButton("z7");
        btnz7.setBounds(610, 362, 49, 42);
        layeredPane.add(btnz7);
        //set the button transparent
        btnz7.setOpaque(false);
        btnz7.setContentAreaFilled(false);
        btnz7.setBorderPainted(false);btnz7.setVisible(false);
        worldMapButtons.add(btnz7);
        
        JButton btnz8 = new JButton("z8");
        btnz8.setBounds(954, 517, 135, 100);
        layeredPane.add(btnz8);
        //set the button transparent
        btnz8.setOpaque(false);
        btnz8.setContentAreaFilled(false);
        btnz8.setBorderPainted(false);
        worldMapButtons.add(btnz8);
        
        JButton btnz9 = new JButton("z9");
        btnz9.setBounds(166, 287, 115, 37);
        layeredPane.add(btnz9);
        //set the button transparent
        btnz9.setOpaque(false);
        btnz9.setContentAreaFilled(false);
        btnz9.setBorderPainted(false);
        worldMapButtons.add(btnz9);
        
        JButton btnz10 = new JButton("z10");
        btnz10.setBounds(108, 150, 204, 136);
        layeredPane.add(btnz10);
        //set the button transparent
        btnz10.setOpaque(false);
        btnz10.setContentAreaFilled(false);
        btnz10.setBorderPainted(false);
        worldMapButtons.add(btnz10);
        
        JButton btnz11 = new JButton("z11");
        btnz11.setBounds(393, 16, 115, 141);
        layeredPane.add(btnz11);
        //set the button transparent
        btnz11.setOpaque(false);
        btnz11.setContentAreaFilled(false);
        btnz11.setBorderPainted(false);
        worldMapButtons.add(btnz11);
        
        JButton btnz12 = new JButton("z12"); //france
        btnz12.setBounds(573, 283, 27, 37);
        layeredPane.add(btnz12);
        //set the button transparent
        btnz12.setOpaque(false);
        btnz12.setContentAreaFilled(false);
        btnz12.setBorderPainted(false);
        worldMapButtons.add(btnz12);
        
        JButton btnz13 = new JButton("z13");//spain
        btnz13.setBounds(550, 316, 27, 29);
        layeredPane.add(btnz13);
        //set the button transparent
        btnz13.setOpaque(false);
        btnz13.setContentAreaFilled(false);
        btnz13.setBorderPainted(false);
        worldMapButtons.add(btnz13);
        
        JButton btnz14 = new JButton("z14");//germany
        btnz14.setBounds(600, 259, 20, 37);
        layeredPane.add(btnz14);
        //set the button transparent
        btnz14.setOpaque(false);
        btnz14.setContentAreaFilled(false);
        btnz14.setBorderPainted(false);
        worldMapButtons.add(btnz14);
        
        JButton btnz15 = new JButton("z15");
        btnz15.setBounds(334, 551, 51, 141);
        layeredPane.add(btnz15);
        //set the button transparent
        btnz15.setOpaque(false);
        btnz15.setContentAreaFilled(false);
        btnz15.setBorderPainted(false);
        worldMapButtons.add(btnz15);
        
        JButton btnz16 = new JButton("z16");
        btnz16.setBounds(350, 517, 35, 29);
        layeredPane.add(btnz16);
        //set the button transparent
        btnz16.setOpaque(false);
        btnz16.setContentAreaFilled(false);
        btnz16.setBorderPainted(false);
        worldMapButtons.add(btnz16);
        
        JButton btnz17 = new JButton("z17");
        btnz17.setBounds(845, 322, 128, 42);
        layeredPane.add(btnz17);
        //set the button transparent
        btnz17.setOpaque(false);
        btnz17.setContentAreaFilled(false);
        btnz17.setBorderPainted(false);btnz17.setVisible(false);
        worldMapButtons.add(btnz17);
        
        JButton btnz18 = new JButton("z18");
        btnz18.setBounds(309, 481, 35, 67);
        layeredPane.add(btnz18);
        //set the button transparent
        btnz18.setOpaque(false);
        btnz18.setContentAreaFilled(false);
        btnz18.setBorderPainted(false);btnz18.setVisible(false);
        worldMapButtons.add(btnz18);
        
        JButton btnz19 = new JButton("z19");
        btnz19.setBounds(808, 369, 63, 100);
        layeredPane.add(btnz19);
        //set the button transparent
        btnz19.setOpaque(false);
        btnz19.setContentAreaFilled(false);
        btnz19.setBorderPainted(false);
        worldMapButtons.add(btnz19);
        
        JButton btnz20 = new JButton("z20");
        btnz20.setBounds(662, 414, 39, 55);
        layeredPane.add(btnz20);
        //set the button transparent
        btnz20.setOpaque(false);
        btnz20.setContentAreaFilled(false);
        btnz20.setBorderPainted(false);
        worldMapButtons.add(btnz20);
        
        for (int i = 0; i <worldMapButtons.size(); i++) 
        {
			worldMapButtons.get(i).setActionCommand(String.valueOf(i));
		}
        
        backButton = new JButton("back");
        backButton.setBounds(1110, 731, 115, 29);
        layeredPane.add(backButton);
        
        
        JLabel label = new JLabel("");
        label.setIcon(new ImageIcon("C:\\sgip\\world-map.jpg"));
        label.setBounds(15, 16, 1222, 700);
        layeredPane.add(label);
        
        JLabel lblClickOnThe = new JLabel("Click on the world map to chose a requested location");
        lblClickOnThe.setFont(new Font("Tahoma", Font.PLAIN, 19));
        lblClickOnThe.setBounds(61, 733, 456, 32);
        layeredPane.add(lblClickOnThe);
	}

	public void addZoneButtonListener(int buttonNumber, ActionListener buttonListener) 
	{
		worldMapButtons.get(buttonNumber).addActionListener(buttonListener);
	}
	
	public void setPaentWindowWithLocation(String location) 
	{
		windowToSetWithLocation.setLocationString(location);
	}
	
	public void clickBackButton()
	{
		backButton.doClick();
	}
}
